Telegram Group & Telegram Channel
🖥 Необходимо определить делегат и реализовать метод

Итак, вот задание:
определить делегат bool CounterHashSetDelegate(int a) и реализовать метод int Function12(HashSet<int> intSet, CounterHashSetDelegate filter), который возвращает количество элементов из intSet, которые удовлетворяют условию filter.
public static  class 
{
public delegate bool CounterHashSetDelegate(int a);
public static int Function12(HashSet<int> intSet, CounterHashSetDelegate filter)
{

int count = 0;
foreach (int i in intSet)
{
if(filter(i))
count++;
}
return count;
}
}



Давайте сразу к сути, решение может выглядеть так:
public delegate bool CounterHashSetDelegate(int a);

class Program
{
static void Main(string[] args)
{
CounterHashSetDelegate d = IsEvenNum;

Console.WriteLine($"Количество четных элементов:{Function12(new HashSet<int> { 1, 2, 3, 4, 5 }, d)}");

d = IsGreaterThen;

Console.WriteLine($"Количество элементов > 2:{Function12(new HashSet<int> { 1, 2, 3, 4, 5 }, d)}");

Console.ReadKey();
}

public static bool IsEvenNum(int a)
{
return a % 2 == 0;// четное ли число например
}

public static bool IsGreaterThen(int a)
{
return a > 2;//больше ли например
}


public static int Function12(HashSet<int> intSet, CounterHashSetDelegate filter)
{

int count = 0;
foreach (int i in intSet)
{
if (filter(i))
{
count++;
}
}
return count;
}

}

Вот и все дела

@csharp_ci
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/csharp_1001_notes/439
Create:
Last Update:

🖥 Необходимо определить делегат и реализовать метод

Итак, вот задание:
определить делегат bool CounterHashSetDelegate(int a) и реализовать метод int Function12(HashSet<int> intSet, CounterHashSetDelegate filter), который возвращает количество элементов из intSet, которые удовлетворяют условию filter.

public static  class 
{
public delegate bool CounterHashSetDelegate(int a);
public static int Function12(HashSet<int> intSet, CounterHashSetDelegate filter)
{

int count = 0;
foreach (int i in intSet)
{
if(filter(i))
count++;
}
return count;
}
}



Давайте сразу к сути, решение может выглядеть так:
public delegate bool CounterHashSetDelegate(int a);

class Program
{
static void Main(string[] args)
{
CounterHashSetDelegate d = IsEvenNum;

Console.WriteLine($"Количество четных элементов:{Function12(new HashSet<int> { 1, 2, 3, 4, 5 }, d)}");

d = IsGreaterThen;

Console.WriteLine($"Количество элементов > 2:{Function12(new HashSet<int> { 1, 2, 3, 4, 5 }, d)}");

Console.ReadKey();
}

public static bool IsEvenNum(int a)
{
return a % 2 == 0;// четное ли число например
}

public static bool IsGreaterThen(int a)
{
return a > 2;//больше ли например
}


public static int Function12(HashSet<int> intSet, CounterHashSetDelegate filter)
{

int count = 0;
foreach (int i in intSet)
{
if (filter(i))
{
count++;
}
}
return count;
}

}

Вот и все дела

@csharp_ci

BY C# 1001 notes




Share with your friend now:
tg-me.com/csharp_1001_notes/439

View MORE
Open in Telegram


C 1001 notes Telegram | DID YOU KNOW?

Date: |

How to Invest in Bitcoin?

Like a stock, you can buy and hold Bitcoin as an investment. You can even now do so in special retirement accounts called Bitcoin IRAs. No matter where you choose to hold your Bitcoin, people’s philosophies on how to invest it vary: Some buy and hold long term, some buy and aim to sell after a price rally, and others bet on its price decreasing. Bitcoin’s price over time has experienced big price swings, going as low as $5,165 and as high as $28,990 in 2020 alone. “I think in some places, people might be using Bitcoin to pay for things, but the truth is that it’s an asset that looks like it’s going to be increasing in value relatively quickly for some time,” Marquez says. “So why would you sell something that’s going to be worth so much more next year than it is today? The majority of people that hold it are long-term investors.”

Telegram announces Anonymous Admins

The cloud-based messaging platform is also adding Anonymous Group Admins feature. As per Telegram, this feature is being introduced for safer protests. As per the Telegram blog post, users can “Toggle Remain Anonymous in Admin rights to enable Batman mode. The anonymized admin will be hidden in the list of group members, and their messages in the chat will be signed with the group name, similar to channel posts.”

C 1001 notes from es


Telegram C# 1001 notes
FROM USA